#ifndef MESSAGE_H
#define MESSAGE_H

#include <apr_network_io.h>
#include "mpi.h"
#include "oom.h"

typedef enum { SENDREQ, SENDOK, SENDMSG } MessageType;

apr_status_t msg_recv_type(apr_socket_t *socket, MessageType *type);
apr_status_t msg_send_type(apr_socket_t *socket, MessageType type);
apr_status_t msg_recv_env(apr_socket_t *socket, Envelope *env);
apr_status_t msg_send_env(apr_socket_t *socket, Envelope *env);
apr_status_t msg_recv_size(apr_socket_t *socket, int *size);
apr_status_t msg_send_size(apr_socket_t *socket, int size);
int msg_env_match(Envelope *sender, Envelope *receiver);
void msg_env_null(Envelope *dst);
void msg_env_copy(Envelope *dst, Envelope *src);
apr_status_t msg_recv_data(apr_socket_t *scoket, void *buf, int count,
	MPI_Datatype datatype, int *bytes_recvd);
apr_status_t msg_send_data(apr_socket_t *socket, void *buf, int count,
	MPI_Datatype datatype);

#endif

